/* M a i n l i n e                                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 2.03  */

#ifdef __USAGE
%C - This is a QNX/Photon Application.
%C [options]

Options:
  -s server   Server node or device name
  -x x        Initial x position
  -y y        Initial y position
  -h h        Initial h dimension
  -w w        Initial w dimension

Examples:
%C -s4
  Run using Photon server on node 4

%C -s//4/dev/photon
  Same as above

%C -x10 -y10 -h200 -w300
  Run at initial position 10,10 with initial 
  dimension of 200x300.
#endif

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"
#include "abwidgets.h"
#include "abdefine.h"
#include "abevents.h"
#include "ablinks.h"
#include "abvars.h"

char AIRPORT_NAME[20];

int
main ( int argc, char *argv[] )

	{

	int c,errflag=0;
	int fd;
	packet_t msg;
	packet_t reply;
	
	if(argc<2)
	{
	    printf("To less arguments.\nUsage: ./a airport_name\n");
	    exit(1);
	}
	
	if((fd = name_open(argv[1],NAME_FLAG_ATTACH_GLOBAL)) == -1)
	{
	    printf("Cannot get to %s\n",argv[1]);
	    exit(1);
	}
	
	while(1)
	{
	    msg.who=GUI; // GUI is sendign message
	    msg.type=GUI_WANT_AIRPORT_DATA; // GUI wants airport data
	    MsgSend(fd,&msg,sizeof(msg),&reply,sizeof(reply));
	    if(reply.who==AIRPORT && reply.type==COMMAND_OK)
	    {
			printf("I've received data:\n");
			printf("Airport Name: %s\n",reply.lotnisko.airportName);
			printf("X position on a map: %d\n",reply.lotnisko.X);
			printf("Y position on a map: %d\n",reply.lotnisko.Y);
			printf("Range radius: %d\n",reply.lotnisko.Range);
			printf("Capacity: %d\n",reply.lotnisko.Capacity);
			printf("Runways Number: %d\n",reply.lotnisko.RunwaysNumber);
			printf("State: %d\n",reply.lotnisko.State);		
			strcpy(AIRPORT_NAME,reply.lotnisko.airportName);
			break;
	    }
	    else
	    {
		printf("Fucki'n hell\n");
	    }
	    sleep(1);
	}
	


	_Ap_.Ap_winstate = 0;

	/* AppBuilder Initialization */
	ApInitialize( argc, argv, &AbContext );

	/* Display main window */
	ApLinkWindow( NULL, &AbApplLinks[0], NULL );

	/* Loop until user quits application */
	PtMainLoop( );
	PtExit( 0 );

	return 0;
	}

static const ApClassTab_t ClassTable[] = {
	{ "PtWindow", &PtWindow },
	{ "PtPanelGroup", &PtPanelGroup },
	{ "PtPane", &PtPane },
	{ "PtRaw", &PtRaw },
	{ "PtTimer", &PtTimer },
	{ "PtScrollContainer", &PtScrollContainer },
	{ NULL, NULL }
	};

ApContext_t AbContext = { ClassTable, 1, AbWidgets };


